package Engine;

import java.io.IOException;
import javax.swing.JOptionPane;

public class Engine {
    
    public void command(String lineCommand_ref, String ip_ref){
        String lineCommand = lineCommand_ref;
        String ip = ip_ref;
        try {
            Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL "
                    + "C:\\Windows\\System32\\cmd.exe /C "
                    + "ECHO "+ lineCommand +">\\\\"+ ip +"\\LP1");
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, "Erro ao usar o Runtime. \n"+ex);
        }
        
    }
    
    public void commandShared(String lineCommand_ref){        
        String lineCommand = lineCommand_ref;        
        String source = "C:\\Windows\\System32\\cmd.exe /C ECHO ";
        String prescribe = lineCommand;
        String exit = ">LPT1";
        String runtime = "rundll32 SHELL32.DLL,ShellExec_RunDLL ";
        String comando = source + prescribe + exit;
        try {
            Runtime.getRuntime().exec(runtime + comando);
            System.out.println(runtime + comando);
        } catch (IOException e) {
        }        
        
    }
    
    public String freeWrite(String free){
        return free;
    }
    
    public String text(String text){
        return "!R! TEXT '" + text + "'; EXIT;";
    }
    
    public String statusPage(){
        return "!R! STAT 0; EXIT;";    
    }
    
    public String serviceStatusPage(){
        return "!R! STAT 1; EXIT;";
    }
    
    public String originalName(){
        return "!R! KCFG \"AREA\", 2; KCFG \"PRDT\", 2; EXIT;";
    }
    
    public String A4_LetterAnulate(){
        return "!R! FRPO S4, 1; EXIT;";
    }
    
    public String pressGOAnulate(){
        return "!R! FRPO Y0, 0; EXIT;";
    }
    
    public String resetAll(){
        return "!R! EGRE; EXIT;";
    }
    
    public String firmwareInt(){
        return "!R! FRPO INIT; EXIT;";
    }
    
    public String adjustFiscalNoteModule1(){
        return "!R! FRPO C1, 1; FRPO P1, 6; FRPO U0, 6; FRPO U1, 50; FRPO U8, 18; "
                + "FRPO D1, 1; FRPO D3, 1; FRPO N4, 0; EXIT;";
    }
    
    public String adjustFiscalNoteModule2(){
        return "!R! FRPO C1, 1; FRPO P1, 6; FRPO U0, 8; FRPO U1, 50; FRPO U8, 19; "
                + "FRPO D1, 1; FRPO D3, 1; FRPO N4, 2; EXIT;";
    }
    
    public String adjustCassetPaperSize(String casset_ref, String size_ref){
        String varCasset = null;
        int varSize;
        if("1".equals(casset_ref)){
            varCasset = "T1";
        }
        
        if("2".equals(casset_ref)){
            varCasset = "T2";
        }
        
        if("3".equals(casset_ref)){
            varCasset = "T3";
        }
        
        if("4".equals(casset_ref)){
            varCasset = "T4";
        }        
                
        if("A4".equals(size_ref)){
            varSize = 8;
            return "FRPO "+ varCasset +", "+ varSize +"; EXIT;";
        }
        
        if("Carta".equals(size_ref)){
            varSize = 6;
            return "FRPO "+ varCasset +", "+ varSize +"; EXIT;";
        }
        
        if("Legal".equals(size_ref)){
            varSize = 7;
            return "FRPO "+ varCasset +", "+ varSize +"; EXIT;";
        }
        
        if("B5".equals(size_ref)){
            varSize = 9;
            return "FRPO "+ varCasset +", "+ varSize +"; EXIT;";
        }
        
        if("A5".equals(size_ref)){
            varSize = 13;
            return "FRPO "+ varCasset +", "+ varSize +"; EXIT;";
        }
        
        return null;
        
    }
    
    public String adjustMPTrayPaperSize(String size_ref){
        int varSize;        
        if("A4".equals(size_ref)){
            varSize = 8;
            return "FRPO R7, "+ varSize +"; EXIT;";
        }
        
        if("Carta".equals(size_ref)){
            varSize = 6;
            return "FRPO R7, "+ varSize +"; EXIT;";
        }
        
        if("Legal".equals(size_ref)){
            varSize = 7;
            return "FRPO R7, "+ varSize +"; EXIT;";
        }
        
        if("B5".equals(size_ref)){
            varSize = 9;
            return "FRPO R7, "+ varSize +"; EXIT;";
        }
        
        if("A5".equals(size_ref)){
            varSize = 13;
            return "FRPO R7, "+ varSize +"; EXIT;";
        }
        
        return null;
        
    }
    
}
